package com.fr.data.impl;

import com.fr.base.Inter;
import com.fr.base.XMLable;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLableReader;
import com.fr.data.ChartData;
import com.fr.data.util.function.SumFunction;

public class TopChartData
  implements ChartData, XMLable
{
  private static final long serialVersionUID = -897581037476181780L;
  public static final String XML_TAG = "TopChartData";
  private ChartData topChartData;
  private int topValue = -1;
  private int topCate = -1;

  public TopChartData()
  {
  }

  public TopChartData(ChartData paramChartData, int paramInt1, int paramInt2)
  {
    this.topChartData = paramChartData;
    setTopValue(paramInt2);
    setTopCate(paramInt1);
  }

  public Object getCategoryLabel(int paramInt)
  {
    if ((paramInt == getTopCate()) && (getTopCate() != -1))
      return Inter.getLocText("ParameterD-The_Other");
    return this.topChartData.getCategoryLabel(paramInt);
  }

  public int getCategoryLabelCount()
  {
    if (this.topChartData == null)
      return 0;
    int i = this.topChartData.getCategoryLabelCount();
    if ((getTopCate() < i) && (getTopCate() != -1))
      return (getTopCate() + 1);
    return i;
  }

  public int getSeriesCount()
  {
    int i = this.topChartData.getSeriesCount();
    if ((getTopValue() < i) && (getTopValue() != -1))
      return (getTopValue() + 1);
    return i;
  }

  public Object getSeriesLabel(int paramInt)
  {
    if (paramInt == getTopValue())
      return Inter.getLocText("ParameterD-The_Other");
    return this.topChartData.getSeriesLabel(paramInt);
  }

  public Number getValueAt(int paramInt1, int paramInt2)
  {
    int i;
    SumFunction localSumFunction = new SumFunction();
    Double localDouble = null;
    if ((getTopCate() == -1) && (getTopValue() != -1))
    {
      if (paramInt1 != getTopValue())
        break label439;
      for (i = getTopValue(); i < this.topChartData.getSeriesCount(); ++i)
        localSumFunction.addData(this.topChartData.getValueAt(i, paramInt2));
      localDouble = Double.valueOf(localSumFunction.getResult().toString());
      return localDouble;
    }
    if ((getTopCate() != -1) && (getTopValue() == -1))
    {
      if (paramInt2 != getTopCate())
        break label439;
      for (i = getTopCate(); i < this.topChartData.getCategoryLabelCount(); ++i)
        localSumFunction.addData(this.topChartData.getValueAt(paramInt1, i));
      localDouble = Double.valueOf(localSumFunction.getResult().toString());
      return localDouble;
    }
    if ((getTopCate() != -1) && (getTopValue() != -1))
    {
      localSumFunction.reset();
      if ((paramInt1 == getTopValue()) && (paramInt2 == getTopCate()))
      {
        for (i = getTopValue(); i < this.topChartData.getSeriesCount(); ++i)
          for (int j = getTopCate(); j < this.topChartData.getCategoryLabelCount(); ++j)
            localSumFunction.addData(this.topChartData.getValueAt(i, j));
        localDouble = Double.valueOf(localSumFunction.getResult().toString());
        return localDouble;
      }
      if ((paramInt1 == getTopValue()) && (paramInt2 < getTopCate()))
      {
        for (i = getTopValue(); i < this.topChartData.getSeriesCount(); ++i)
          localSumFunction.addData(this.topChartData.getValueAt(i, paramInt2));
        localDouble = Double.valueOf(localSumFunction.getResult().toString());
        return localDouble;
      }
      if ((paramInt1 < getTopValue()) && (paramInt2 == getTopCate()))
      {
        for (i = getTopCate(); i < this.topChartData.getCategoryLabelCount(); ++i)
          localSumFunction.addData(this.topChartData.getValueAt(paramInt1, i));
        localDouble = Double.valueOf(localSumFunction.getResult().toString());
        return localDouble;
      }
    }
    label439: return this.topChartData.getValueAt(paramInt1, paramInt2);
  }

  public void setTopValue(int paramInt)
  {
    this.topValue = paramInt;
  }

  public int getTopValue()
  {
    return this.topValue;
  }

  public void setTopCate(int paramInt)
  {
    this.topCate = paramInt;
  }

  public int getTopCate()
  {
    return this.topCate;
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isChildNode())
    {
      String str1 = paramXMLableReader.getTagName();
      if (str1.equals("Top"))
      {
        String str2;
        if ((str2 = paramXMLableReader.getAttr("topCate")) != null)
          setTopCate(Integer.parseInt(str2));
        if ((str2 = paramXMLableReader.getAttr("topValue")) != null)
          setTopValue(Integer.parseInt(str2));
      }
      else if (str1.equals("ReportChartData"))
      {
        this.topChartData = ((XMLable)paramXMLableReader.readXMLObject(new ReportChartData()));
      }
      else if (str1.equals("TableChartData"))
      {
        this.topChartData = ((XMLable)paramXMLableReader.readXMLObject(new TableChartData()));
      }
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("TopChartData");
    paramXMLPrintWriter.startTAG("Top").attr("topCate", getTopCate()).attr("topValue", getTopValue()).end();
    if (this.topChartData != null)
      this.topChartData.writeXML(paramXMLPrintWriter);
    paramXMLPrintWriter.end();
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof TopChartData))
      return false;
    TopChartData localTopChartData = (TopChartData)paramObject;
    if (localTopChartData.getTopCate() != getTopCate())
      return false;
    if (localTopChartData.getTopValue() != getTopValue())
      return false;
    return (localTopChartData.topChartData.equals(this.topChartData));
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    TopChartData localTopChartData = new TopChartData();
    return localTopChartData;
  }
}